package utils

import (
	"strconv"
	"strings"
)

func StrToInt(str string) (num int) {
	num, err := strconv.Atoi(str)
	if err != nil {
		num = 0
	}
	return num
}

func StrToInt32(str string) (num int64) {
	num, err := strconv.ParseInt(str, 10, 32)
	if err != nil {
		num = 0
	}
	return num
}
func StrToInt64(str string) (num int64) {
	num, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		num = 0
	}
	return num
}

func StrToFloat(str string) (num float64) {
	num, _ = strconv.ParseFloat(str, 64)
	return num
}

func StrToBool(str string) (b bool) {
	valstr := strings.ToLower(str)
	switch valstr {
	case "true":
		return true
	case "1":
		return true
	}
	return false
}
